package com.app.core.util;

import com.app.core.config.Constants;
import com.app.core.config.MyApp;
import com.specialtreasure.freightdepot.model.Data;
import com.specialtreasure.freightdepot.model.Login;
import com.specialtreasure.freightdepot.model.User;

/**
 * Created by Administrator on 2017/8/9 0009.
 * 用户信息工具类
 */

public class UserUtils {

    /**
     * 用户token
     * @return
     */
    public static String getToken() {
        String token = null;
        Login login = (Login) MyApp.getInstance().getaCache().getAsObject(Constants.LOGIN);
        if (login != null) {
            Data data = login.getData();
            if (data != null) {
                token = data.getToken();
            }
        }

        return token;
    }

    public static Integer getUserId(){
        Integer userId = null;
        Login login = (Login) MyApp.getInstance().getaCache().getAsObject(Constants.LOGIN);
        if (login != null) {
            Data data = login.getData();
            if (data != null) {
                User user = data.getUser();
                if (user!=null){
                    userId=user.getUserId();
                }
            }
        }

        return userId;
    }





    /**
     * 注销
     */
    public static void logout(){
        MyApp.getInstance().getaCache().remove(Constants.LOGIN);
//        MyApp.getInstance().getaCache().remove(Constants.USERNAME);
//        MyApp.getInstance().getaCache().remove(Constants.PASSWORD);
    }

}
